﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace Lan.Core.DataBase
{
    public class BaseService<T>:IBaseService<T> where T : class, new()
    {
        protected ISimpleClient<T> BaseRepository;
        protected BaseService(ISimpleClient<T> baseBaseRepository)
        {
            BaseRepository = baseBaseRepository;
        }

        public bool Delete(Expression<Func<T, bool>> whereExpression)
        {
            return BaseRepository.Delete(whereExpression);
        }

        public bool Delete(T deleteObj)
        {
            return BaseRepository.Delete(deleteObj);
        }

        public Task<bool> DeleteAsync(Expression<Func<T, bool>> whereExpression)
        {
            return BaseRepository.DeleteAsync(whereExpression);
        }

        public Task<bool> DeleteAsync(T deleteObj)
        {
            return BaseRepository.DeleteAsync(deleteObj);
        }

        public bool DeleteById(dynamic id)
        {
            return BaseRepository.DeleteById(id);
        }

        public Task<bool> DeleteByIdAsync(dynamic id)
        {
            return BaseRepository.DeleteByIdAsync(id);
        }

        public bool DeleteByIds(dynamic[] ids)
        {
            return BaseRepository.DeleteByIds(ids);
        }

        public Task<bool> DeleteByIdsAsync(dynamic[] ids)
        {
            return BaseRepository.DeleteByIdsAsync(ids);
        }

        public T GetById(dynamic id)
        {
            return BaseRepository.GetById(id);
        }

        public Task<T> GetByIdAsync(dynamic id)
        {
            return BaseRepository.GetByIdAsync(id);
        }

        public List<T> GetList()
        {
            return BaseRepository.GetList();
        }

        public List<T> GetList(Expression<Func<T, bool>> whereExpression)
        {
            return BaseRepository.GetList(whereExpression);
        }

        public Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression)
        {
            return BaseRepository.GetListAsync(whereExpression);
        }

        public Task<List<T>> GetListAsync()
        {
            return BaseRepository.GetListAsync();
        }

        public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
        {
            return BaseRepository.GetPageList(whereExpression,page,orderByExpression,orderByType);
        }

        public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page)
        {
            return BaseRepository.GetPageList(whereExpression, page);
        }

        public Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page)
        {
            return BaseRepository.GetPageListAsync(whereExpression,page);
        }

        public Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
        {
            return BaseRepository.GetPageListAsync(whereExpression, page, orderByExpression, orderByType);
        }

        public T GetSingle(Expression<Func<T, bool>> whereExpression)
        {
            return BaseRepository.GetSingle(whereExpression);
        }

        public Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression)
        {
            return BaseRepository.GetSingleAsync(whereExpression);
        }

        public bool Insert(T model)
        {
            return BaseRepository.Insert(model);
        }

        public Task<bool> InsertAsync(T model)
        {
            return BaseRepository.InsertAsync(model);
        }

        public bool InsertList(List<T> list)
        {
            return BaseRepository.InsertRange(list);
        }

        public Task<bool> InsertListAsync(List<T> list)
        {
            return BaseRepository.InsertRangeAsync(list);
        }

        public int InsertReturnIdentity(T model)
        {
            return BaseRepository.InsertReturnIdentity(model);
        }

        public Task<int> InsertReturnIdentityAsync(T model)
        {
            return BaseRepository.InsertReturnIdentityAsync(model);
        }

        public bool IsAny(Expression<Func<T, bool>> whereExpression)
        {
            return BaseRepository.IsAny(whereExpression);
        }

        public Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression)
        {
            return BaseRepository.IsAnyAsync(whereExpression);
        }

        public bool Update(T model)
        {
            return BaseRepository.Update(model);
        }

        public bool Update(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression)
        {
            return BaseRepository.Update(columns, whereExpression);
        }

        public Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression)
        {
            return BaseRepository.UpdateAsync(columns,whereExpression);
        }

        public Task<bool> UpdateAsync(T model)
        {
            return BaseRepository.UpdateAsync(model);
        }

        public bool UpdateList(List<T> list)
        {
            return BaseRepository.UpdateRange(list);
        }

        public Task<bool> UpdateListAsync(List<T> list)
        {
            return BaseRepository.UpdateRangeAsync(list);
        }
    }
}
